using System;
namespace Servlets.Api
{
	/// <summary>
	/// Enum of the different Http Properties sent in an HTTP Header.
	/// HttpProperties are compared by their string value.
	/// This class was made to provide type safety for the common Http Properties.
	/// However, a standard Enum was not used because any Http Property can be set.
	/// If there is a value already defined in this class, it should be used.
	/// </summary>
	public class HttpProperty
	{	
		public readonly static HttpProperty ContentLength = new HttpProperty("Content-Length");
		public readonly static HttpProperty ContentType = new HttpProperty("Content-Type");
		public readonly static HttpProperty Cookie = new HttpProperty("Cookie");
		//TODO: Add all the common/standard Http Properties
		
		/// <summary>
		/// The string value of the Http Property.
		/// </summary>
		public string Name{get;private set;}

		/// <summary>
		/// Creates 
		/// </summary>
		/// <param name="name">
		/// A <see cref="System.String"/>
		/// </param>
		public HttpProperty(string name)
		{
			this.Name = name.Trim();
			if(Name.EndsWith(":")) {
				Name = Name.Substring(0, Name.Length-1);
			}
		}
		
		public override bool Equals(object obj)
		{
			HttpProperty o = obj as HttpProperty;
			if(o == null) {
				return false;
			}
			return this.Name == o.Name;
		}
		
		public override int GetHashCode()
		{
			return this.Name.GetHashCode();
		}
		
		public override string ToString()
		{
			return Name;
		}
		
		public static explicit operator HttpProperty(string arg)
		{
			return new HttpProperty(arg);
		}
	}
}

